<template>
  <VDialog
    @close="handleClose"
    @save="save"
    :loading="loading"
    width="700px"
    title="自动禁用账号设置"
  >
    <template #content>
      <div class="flex items-center m-[20px]">
        <span>用户在</span>
        <el-input
          v-model="dayNum"
          :minlength="1"
          type="Number"
          min="0"
          class="w-[150px] mx-[16px]"
        /><span>天未登录系统，则自动禁用账号，需走OA审批重新启用账号！</span>
      </div>
    </template>
  </VDialog>
</template>
<script setup>
import { ElMessage } from "element-plus";
import api from "../../api/index";
const props = defineProps({
  day: { type: [Number, String], default: 0 },
});
const { data } = toRefs(props);
const dayNum = ref(0);
watch(
  () => props.day,
  (val) => {
    dayNum.value = val;
  }
);
const emit = defineEmits(["update:modelValue", "close", "refresh"]);
const loading = ref(false);
const handleClose = async (refresh) => {
  emit("update:modelValue", false);
  emit("close");
  if (refresh) emit("refresh");
};
const save = async () => {
  try {
    loading.value = true;
    const { code, message } = await api.setDisableAccount({
      day_in_not_login: dayNum.value,
    });
    if (code !== 200) return ElMessage.error(message);
    ElMessage.success("设置成功!");
    handleClose(true);
  } catch (error) {
  } finally {
    loading.value = false;
  }
};
</script>
